fix(editor): restore highlighting after format and refactor editor sync state (#1612)#1616
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1612. Also carries the behavior-neutral refactor of the editor sync and completion state that #1608/#1612 exposed. Replaces #1615.
Part 1: fix for #1612 (highlighting lost after Format)
Two layers:
syncBindingTextcalled the TextView-leveltextView.setText(...), bypassingTextViewController.setText(_:), the documented controller-level path that rebuilds the highlighter for the replacement storage. The old highlighter kept tree-sitter state for the dead document.Highlighteronly queries when triggered (an edit, a frame/bounds notification, orinvalidate()). Initial load works because the first layout pass firesframeDidChangeNotification; after a mid-session storage swap no trigger is guaranteed.setUpHighlighter()now ends withhighlighter.invalidate(), making "after setup, the editor is highlighted" an invariant instead of a timing accident.Tests:
test_syncRebuildsHighlighterForReplacementStorage,test_syncQueriesHighlightsForReplacementStorage(mock provider proves the rebuilt highlighter is re-set-up AND re-queried; fails with the route-through change alone).Part 2: refactor of text binding sync (package)
The coordinator juggled four pieces of implicit state (
isUpdatingFromRepresentable,isUpdateFromTextView,lastSyncedText,textBindingTask); both recent bugs were interactions between them. Now:RepresentableSyncPhase: explicit origin state machine (idle/editorChangePending/applyingRepresentableValue). The mutual exclusion the booleans only implied is enforced by construction.TextBindingSync: single owner of writeback (sync + large-doc debounce) and push-down, carrying the documented invariants (editor wins while its edit is in flight; push-down routes throughTextViewController.setText).updateNSViewControllershrink to thin delegation.All 11 binding-sync behavior tests pass unchanged in meaning (retargeted in the same commit), plus 5 new state-machine transition tests.
Part 3: refactor of completion sessions (package + app)
SQLCompletionAdapterreplaces three ad-hoc fields (currentCompletionContextthat was never cleared,suppressNextCompletion, a hand-rolled debounce generation counter) with oneCompletionSessioncarrying an explicit phase (intermediatekeyword seed ->finalfull result), the immediate-sync-then-async-refine shapeNSTextSuggestionsDelegatedocuments.SuggestionViewModel(isApplyingCompletionaround the delegate apply call), fixing it for every delegate instead of each adapter keeping its own flag.completionWindowDidClose()was declared on the delegate protocol but never invoked;willClose()now calls it, and the adapter uses it to end the session, so context no longer leaks across popups.New tests: trigger-during-apply ignored,
willClosenotifies the delegate once. All 6 app autocomplete suites pass (366 cases).Manual checks worth doing
Type (popup filters per keystroke), accept with Tab/Return (no flicker after accept), Format (highlighting survives), Clear, JSON viewer session.